Skip to content

subplot titles respecting row_width and column_width #1245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 30, 2018

Conversation

Kully
Copy link
Contributor

@Kully Kully commented Oct 26, 2018

issue: #1229

Going to write some tests that ensure that subtitles are in the right place w/ row_/column_width, if none exist already.

Still fixing broken tests

newplot

newplot 1

@Kully
Copy link
Contributor Author

Kully commented Oct 26, 2018

@jonmmease ready for a review

Copy link
Contributor

@jonmmease jonmmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on @Kully! A few comments/questions inline.

Also, do we have any tests that would make sure that this rowspan example from the docs is still working (https://plot.ly/python/subplots/#custom-sized-subplot-with-subplot-titles)?

Thanks!


def test_row_width_and_column_width(self):

expected = Figure({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an image of this expected figure to the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a png in the file? I am not aware of image tests for this repo but I could be wrong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I just meant in the GitHub PR so I could see what it looks like 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newplot

plotly/tools.py Outdated
@@ -1080,6 +1079,7 @@ def _get_anchors(r, c, x_cnt, y_cnt, shared_xaxes, shared_yaxes):
return x_anchor, y_anchor

list_of_domains = [] # added for subplot titles
list_of_domains_complete = [] # hold onto every domain used, even if shared axes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope - I'll ⚡️

plotly/tools.py Outdated
subtitle_pos_y = [None] * rows
delt_x = (x_e - x_s)
x_dom = [layout[k]['domain'] for k in sorted(layout.to_plotly_json().keys()) if 'xaxis' in k]
y_dom = [layout[k]['domain'] for k in sorted(layout.to_plotly_json().keys()) if 'yaxis' in k]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this sort going to break down when there are more than 9 xaxes? e.g. ['xaxis', 'xaxis10', 'xaxis2', 'xaxis3', ...]
I'm thinking we might need to pluck off the digits and sort them as integers. Could you try an example with 11 or 12 rows and see if there's an issue? If there is an issue, let's make it a test 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch - I'll make sure it's full proof

subtitle_pos_x.append(sum(x_domains) / 2)
subtitle_pos_x *= rows

if shared_yaxes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any tests that specify row_width and hit this branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, i'll write one

@jonmmease
Copy link
Contributor

Code looks good. Last thing, could you add a screenshot (in the PR) and test for this example from the documentation: https://plot.ly/python/subplots/#custom-sized-subplot-with-subplot-titles

I want to make sure this doesn't break cases with colspan and then 🔒 it in. Thanks!

@jonmmease jonmmease added this to the v3.4.0 milestone Oct 30, 2018
@Kully
Copy link
Contributor Author

Kully commented Oct 30, 2018

could you add a screenshot (in the PR) and test for this example from the documentation

Looks good to me.

newplot 1

@jonmmease
Copy link
Contributor

Great! Just make it a test and we're good to go. I'll merge it in tonight. Thanks!

@Kully
Copy link
Contributor Author

Kully commented Oct 30, 2018

Just make it a test and we're good to go

we already have a test that already tests this example except for the data: https://github.com/plotly/plotly.py/blob/master/plotly/tests/test_core/test_tools/test_make_subplots.py#L2086-L2090

Do you want something that also checks the data or is't it good enough that the layout is being tested?

@jonmmease
Copy link
Contributor

No, that covers it. Didn't realize we had this one already! 💃

@jonmmease jonmmease merged commit 5305f74 into master Oct 30, 2018
@jonmmease jonmmease deleted the make_subplots_titles branch October 30, 2018 14:44
michaelbabyn pushed a commit to michaelbabyn/plotly.py that referenced this pull request Dec 22, 2018
* first pass at subplot titles respecting row_width and column_width
* add test for row_width and column_width in make_subplots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants